<?php
/*
 * 通用异步任务队列业务处理脚本
 * @version 2021/12/2
 * */

//引入shell bootstrap
require_once __DIR__ . '/../BaseShell.php';

set_time_limit(0);

$list_key = Module_Queue_Base::$repair_key;

while(true){
    $task = Lib_Redis_List::rPop($list_key);
    if(!$task){
	    sleep(1);
        continue;
    }
    $task = unserialize($task);
     Func_Log::write('Queue','outQueueSuccess','task_id : '.$task['data']['task_id'].' data : '.json_encode($task['data']));
    //业务处理的类名和方法名
    $class_name = $task['type'];
    $method_name = $task['method'] . 'Handler';
    if(!method_exists($class_name,$method_name)){
         Func_Log::write('Queue','outQueueError_'.$task['data']['task_id'],$class_name.'['.$method_name.']_not_exist');
        continue;
    }

    $res = call_user_func(array($class_name, $method_name), $task['data']);
    Func_Log::write('Queue', $task['data']['task_id'], 'task_res::' . json_encode($res));
}
